<!DOCTYPE html>
<HTML>
<HEAD><meta name="viewport" content="width=device-width, initial-scale=1">
<Title>Tree Map Layout</Title>
<link type='text/css' rel='Stylesheet' href="maxchartapi.css" />
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">

<p class="heading0">ChartDirector 7.0 (Java Edition)</p>
<p class="heading1">Tree Map Layout</p>
<hr class="separator">
<div class="content">
<img src="images/treemaplayout0.png" width='300' height='300'>&nbsp;&nbsp;<img src="images/treemaplayout1.png" width='300' height='300'>&nbsp;&nbsp;<img src="images/treemaplayout2.png" width='300' height='300'>&nbsp;&nbsp;<img src="images/treemaplayout3.png" width='300' height='300'>&nbsp;&nbsp;<img src="images/treemaplayout4.png" width='300' height='300'>
<br><br>
The example demonstrates various tree map layout methods configurable using <a href="TreeMapNode.setLayoutMethod.htm">TreeMapNode.setLayoutMethod</a>.
</div>
<p class="heading1a">Source Code Listing</p>
<div class="content">
<b>[JSP Version]</b> jspdemo/treemaplayout.jsp
<div class='codeblock'><code class='pre'>&lt;%@page import="ChartDirector.*, java.util.*" %&gt;
&lt;%!
// Function to create the demo charts
void createChart(WebChartViewer viewer, int chartIndex)
{
    // Random data for the tree map
    RanSeries r = new RanSeries(3);
    double[] data = r.getSeries(20, 20, 400);

    // Create a Tree Map object of size 300 x 300 pixels
    TreeMapChart c = new TreeMapChart(300, 300);
    c.setPlotArea(20, 20, 260, 260);

    // Obtain the root of the tree map, which is the entire plot area
    TreeMapNode root = c.getRootNode();

    // Add first level nodes to the root.
    root.setData(data);

    if (chartIndex == 0) {
        // Squarity - Layout the cells so that they are as square as possible.
        c.addTitle("Squarify");
        root.setLayoutMethod(Chart.TreeMapSquarify);
    } else if (chartIndex == 1) {
        // Strip layout - Cells flow from left to right, top to bottom. The number of cells in each
        // row is such that they will be as close to a square as possible. (The setLayoutMethod also
        // supports other flow directions.)
        c.addTitle("Strip");
        root.setLayoutMethod(Chart.TreeMapStrip);
    } else if (chartIndex == 2) {
        // Binary Split by Size - Split the cells into left/right groups so that their size are as
        // close as possible. For each group, split the cells into top/bottom groups using the same
        // criteria. Continue until each group contains one cell. (The setLayoutMethod also supports
        // other flow directions.)
        c.addTitle("Binary Split by Size");
        root.setLayoutMethod(Chart.TreeMapBinaryBySize);
    } else if (chartIndex == 3) {
        // Binary Split by Count - Same as "Binary Split by Size", except that the cell count
        // (instead of the size) is used to split the cells.
        c.addTitle("Binary Split by Count");
        root.setLayoutMethod(Chart.TreeMapBinaryByCount);
    } else if (chartIndex == 4) {
        // Binary Split by Size (Sorted) - Same as "Binary Split by Size" except the cells are
        // sorted first.
        c.addTitle("Binary Split by Size (Sorted)");
        root.setSorting(-1);
        root.setLayoutMethod(Chart.TreeMapBinaryBySize);
    }

    // Get the prototype (template) for the first level nodes.
    TreeMapNode nodeConfig = c.getLevelPrototype(1);

    // Set the label format for the nodes to show the label and value with 8pt Arial Bold font in
    // black color (000000) and center aligned in the node.
    nodeConfig.setLabelFormat("{index}", "Arial", 8, 0x000000, Chart.Center);

    // Set automatic fill color and white (ffffff) border
    nodeConfig.setColors(Chart.DataColor, 0xffffff);

    // Output the chart
    viewer.setChart(c, Chart.SVG);

    // Include tool tip for the chart
    viewer.setImageMap(c.getHTMLImageMap("", "", "title='&lt;*cdml*&gt;&lt;*b*&gt;[{index}]&lt;*/b*&gt; {value|2}'"));
}
%&gt;
&lt;%
// This example includes 5 charts
WebChartViewer[] viewers = new WebChartViewer[5];
for (int i = 0; i &lt; viewers.length; ++i) {
    viewers[i] = new WebChartViewer(request, "chart" + i);
    createChart(viewers[i], i);
}
%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Tree Map Layout&lt;/title&gt;
    &lt;!-- Include ChartDirector Javascript Library to support chart interactions --&gt;
    &lt;script type="text/javascript" src="cdjcv.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body style="margin:5px 0px 0px 5px"&gt;
    &lt;div style="font:bold 18pt verdana;"&gt;
        Tree Map Layout
    &lt;/div&gt;
    &lt;hr style="border:solid 1px #000080; background:#000080" /&gt;
    &lt;div style="font:10pt verdana; margin-bottom:1.5em"&gt;
        &lt;a href="viewsource.jsp?file=&lt;%=request.getServletPath()%&gt;"&gt;View Source Code&lt;/a&gt;
    &lt;/div&gt;
    &lt;!-- ****** Here are the chart images ****** --&gt;
    &lt;%
        for (int i = 0; i &lt; viewers.length; ++i) {
            out.write(viewers[i].renderHTML(response));
            out.write(" ");
        }
    %&gt;
&lt;/body&gt;
&lt;/html&gt;</code></div>
</div>
<br><hr class="separator"><div class="copyright">&copy; 2022 Advanced Software Engineering Limited. All rights reserved.</div>
</body>
</HTML>
